import { WebSocketService } from './ws-service'

class WebSocketManager {
  constructor() {
    this.wsService = null
  }

  static getInstance() {
    if (!this.instance) {
      this.instance = new WebSocketManager()
    }

    return this.instance
  }

  initService(config) {
    if (!this.wsService) {
      this.wsService = new WebSocketService(config)
      this.wsService.connect()
    }
  }

  getService() {
    return this.wsService
  }

  destroyService() {
    if (this.wsService) {
      this.wsService.disconnect()
      this.wsService = null
    }
  }
}

export const wsManager = WebSocketManager.getInstance()
